package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.CheckInConfigMapper;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {

    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Autowired
    private CheckInConfigMapper checkInConfigMapper;


    @Override
    public PageResponse<NursingLevelVo> findNursingLevelPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLevelVo> pageInfo = nursingLevelMapper.findNursingLevelPage(name, status);
        pageInfo.getResult().forEach(nursingLevelVo -> {
            nursingLevelVo.setCount(checkInConfigMapper.findRefByNursingLevelId(nursingLevelVo.getId()));
        });
        return PageResponse.of(pageInfo, NursingLevelVo.class);
    }

    @Override
    public void addNursingLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.addNursingLevel(nursingLevel);
    }

    @Override
    public NursingLevelVo findNursingLevelById(Long id) {
        return nursingLevelMapper.findNursingLevelById(id);
    }

    @Override
    public void updateNursingLevel(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto, NursingLevel.class);
        nursingLevelMapper.updateNursingLevel(nursingLevel);
    }

    @Override
    public void deleteNursingLevel(Long id) {
        nursingLevelMapper.deleteNursingLevel(id);
    }

    @Override
    public void updateNursingLevelByStatus(Long id, Integer status) {
        nursingLevelMapper.updateNursingLevelByStatus(id, status);
    }

    @Override
    public List<NursingLevelVo> findAllNursingLevel() {
        return nursingLevelMapper.findAllNursingLevel();
    }
}
